<template>
<div class="adress">
<router-link to="/adressPush">
<van-nav-bar
  title="请输入您的地址"
  left-text="返回"
  right-text="查看保存"
  left-arrow
  @click-left="onClickLeft"
/>
</router-link>
<van-address-edit
  :area-list="areaList"
  show-postal
  show-delete
  show-set-default
  show-search-result
  :search-result="searchResult"
  :area-columns-placeholder="['请选择', '请选择', '请选择']"
  @save="onSave"
  @delete="onDelete"
  @change-detail="onChangeDetail"
/>
</div>
</template>

<script>
import { Toast } from 'vant'
import { areaList } from '@vant/area-data'
export default {
  name: 'adress',
  created() {
    console.log(this.$route)
  },
  data() {
    return {
      areaList,
      searchResult: [],
      arr: [],
    }
  },
  methods: {
    onSave(result) {
      Toast('保存成功')
      const currentAdress = {
        name: result.name,
        tel: result.tel,
        address: result.addressDetail,
        isDefault: true,
      }
      this.$store.commit('addToAdress', currentAdress)
      this.$router.push('/adressPush')
    },
    onDelete() {
      Toast('已删除')
    },
    onChangeDetail(val) {
      if (val) {
        this.searchResult = [
          {
            name: '肖家河大厦',
            address: '四川省成都市武侯区',
          },
        ]
      } else {
        this.searchResult = []
      }
    },
    onClickLeft() {
      this.$router.back()
    },
  },
}
</script>

<style lang="scss" scoped>

</style>
